﻿namespace BloggerBackup
{
    using Microsoft.VisualBasic;
    using Microsoft.VisualBasic.CompilerServices;
    using System;
    using System.Collections.Generic;
    using System.Drawing;
    using System.IO;
    using System.Runtime.Serialization.Formatters.Binary;

    [Serializable]
    public class BloggerBackupSettings
    {
        private List<BlogSetting> _blogSettings = new List<BlogSetting>();
        private bool _changed;
        private string _defaultBackupPath = "";
        private SelectedSaveNameOptions _defaultSaveNameOptions;
        private string _defaultUserName = "";
        private Point _formLocation = new Point(-1, -1);
        private Size _formSize = new Size(-1, -1);
        private BlogSetting _lastUsedBlog = null;
        private bool _proxyEnabled = false;
        private string _proxyPassword = "";
        private int _proxyPort = 0;
        private string _proxyURL = "";
        private string _proxyUserId = "";
        public const string DEFAULT_EXTENSION = "BBSettings";
        public const string DEFAULT_FILENAME = "BloggerBackup";

        public static BloggerBackupSettings Load(string settingsPath)
        {
            FileStream serializationStream = null;
            BloggerBackupSettings settings = new BloggerBackupSettings();
            try
            {
                serializationStream = new FileStream(settingsPath, FileMode.OpenOrCreate, FileAccess.Read);
                if (serializationStream.Length > 0L)
                {
                    BinaryFormatter formatter = new BinaryFormatter();
                    settings = (BloggerBackupSettings) formatter.Deserialize(serializationStream);
                    settings.Changed = false;
                }
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exception = exception1;
                Interaction.MsgBox("Error loading Settings file, " + settingsPath + "\r\n\r\n" + exception.Message, MsgBoxStyle.OkOnly, null);
                ProjectData.ClearProjectError();
            }
            finally
            {
                serializationStream.Close();
                serializationStream.Dispose();
            }
            return settings;
        }

        public static bool Save(BloggerBackupSettings settings, string settingsPath)
        {
            bool flag;
            FileStream serializationStream = new FileStream(settingsPath, FileMode.Create, FileAccess.Write);
            new BinaryFormatter().Serialize(serializationStream, settings);
            settings.Changed = false;
            serializationStream.Close();
            serializationStream.Dispose();
            return flag;
        }

        public List<BlogSetting> BlogSettings
        {
            get
            {
                return this._blogSettings;
            }
            set
            {
                this._blogSettings = value;
                this.Changed = true;
            }
        }

        public bool Changed
        {
            get
            {
                return this._changed;
            }
            set
            {
                this._changed = value;
            }
        }

        public string DefaultBackupPath
        {
            get
            {
                return this._defaultBackupPath;
            }
            set
            {
                this._defaultBackupPath = value;
                this.Changed = true;
            }
        }

        public SelectedSaveNameOptions DefaultSaveNameOptions
        {
            get
            {
                return this._defaultSaveNameOptions;
            }
            set
            {
                this._defaultSaveNameOptions = value;
                this.Changed = true;
            }
        }

        public string DefaultUserName
        {
            get
            {
                return this._defaultUserName;
            }
            set
            {
                this._defaultUserName = value;
                this.Changed = true;
            }
        }

        public Point FormLocation
        {
            get
            {
                return this._formLocation;
            }
            set
            {
                this._formLocation = value;
                this.Changed = true;
            }
        }

        public Size FormSize
        {
            get
            {
                return this._formSize;
            }
            set
            {
                this._formSize = value;
                this.Changed = true;
            }
        }

        public BlogSetting LastUsedBlog
        {
            get
            {
                return this._lastUsedBlog;
            }
            set
            {
                this._lastUsedBlog = value;
            }
        }

        public bool ProxyEnabled
        {
            get
            {
                return this._proxyEnabled;
            }
            set
            {
                this._proxyEnabled = value;
                this.Changed = true;
            }
        }

        public string ProxyPassword
        {
            get
            {
                return this._proxyPassword;
            }
            set
            {
                this._proxyPassword = value;
                this.Changed = true;
            }
        }

        public int ProxyPort
        {
            get
            {
                return this._proxyPort;
            }
            set
            {
                this._proxyPort = value;
                this.Changed = true;
            }
        }

        public string ProxyURL
        {
            get
            {
                return this._proxyURL;
            }
            set
            {
                this._proxyURL = value;
                this.Changed = true;
            }
        }

        public string ProxyUserId
        {
            get
            {
                return this._proxyUserId;
            }
            set
            {
                this._proxyUserId = value;
                this.Changed = true;
            }
        }
    }
}

